package com.pcs.service.impl;

import com.pcs.dao.MassageMapper;
import com.pcs.pojo.Massage;
import com.pcs.pojo.MassageExample;
import com.pcs.service.IMassageService;
import com.pcs.utils.SMSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service("massageService")
public class MassageServiceImpl implements IMassageService {

    @Autowired
    MassageMapper massageMapper;

    @Override
    public Massage SelectByPhoneAndCode(String phone, String code) {
        MassageExample example =new MassageExample();
        MassageExample.Criteria criteria = example.createCriteria();
        criteria.andPhoneEqualTo(phone).andCodeEqualTo(code);
        List<Massage> result= massageMapper.selectByExample(example);
        if(result.isEmpty())
            return null;
        else{
            //TODO
//            Date day=new Date();
//            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            Massage re = result.get(0);
//            if(SMSUtils.overtimeCode(re.getCreateTime(),day,120)){
//                return null;
//            }
        }
        Massage massage = result.get(0);
        System.out.println("!!!!!MMM"+massage.getPhone());
        return result.get(0);
    }

    @Override
    public Massage SavePhoneAndCode(String phone, String code) {
        Massage massage = new Massage();
        massage.setPhone(phone);
        massage.setCode(code);
        massage.setCreateTime(new Date());
        massageMapper.insert(massage);
        return null;
    }
}
